package com.chc.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {

	private static SimpleDateFormat sy = new SimpleDateFormat("yyyy");
	private static SimpleDateFormat sm = new SimpleDateFormat("yyyy-MM");
	private static SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
	private static SimpleDateFormat st = new SimpleDateFormat("HH:mm:ss");
	private static SimpleDateFormat sdt = new SimpleDateFormat(
			"yyyy/MM/dd HH:mm:ss");
	
	public String formatDate(Date date) {
		return sd.format(date);
	}

	public String formatDateTime(Date date) {
		return sdt.format(date);
	}

	public Date parseDate(String s) throws ParseException {
		return sd.parse(s);
	}

	public static Date parseDateTime(String s) throws ParseException {
		return sdt.parse(s);
	}
	
	public static String getDate(Date date) {
		return sd.format(date);
	}

	public static String getDateTime(Date date) {
		return sdt.format(date);
	}
	
	public static String toyear() {
		return sy.format(new Date());
	}

	public static String tomonth() {
		return sm.format(new Date());
	}

	public static String today() {
		return sd.format(new Date());
	}

	public static String now() {
		return st.format(new Date());
	}

	public static String getFullTime() {
		return sdt.format(new Date());
	}
	/**
	 * 
	 * @param date 时间
	 * @param field 将要设置的日历字段
	 * @param num 设置的值
	 * @return
	 */
	public static Date getDate(Date date,int field,int num){
		Calendar c=Calendar.getInstance();
		c.setTime(date);
		c.add(field, num);
		return c.getTime();
	}

	
}
